﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace EsriGridToRaw
{
    public class FileLoader
    {
        FileStream inFile;

        int bufferpos;
        int buffersize = 1024;
        public bool loaded = false;
        byte[] data;

        public FileLoader(string filepath)
        {
            try
            {
                inFile = new FileStream(filepath, FileMode.Open, FileAccess.Read);
                data = new byte[buffersize];
                readNextBuffer();
                loaded = true;
            }
            catch
            {
                throw;
            }
        }

        public void readNextBuffer()
        {
            int read = inFile.Read(data, 0, buffersize);
            for (int i = read; i < buffersize; i++)
            {
                data[i] = 0;
            }
            bufferpos = 0;
        }

        public byte readNext()
        {
            if(bufferpos>=buffersize) readNextBuffer();
            byte w = data[bufferpos];
            bufferpos++;
            return w;
        }

    }
}
